package qy.qyalgotrader.utils.plotter;

import qy.jalgotrade.bar.Bar;
import qy.jalgotrade.bar.Bar.Frequency;

import java.time.ZonedDateTime;

/**
 * @author qy
 *
 */
public class RealtimeInstrumentMarker extends RealtimeSeries<Bar, Double> {

	private boolean __useAdjClose;

	private String __marker;

	/**
	 * 
	 * @param frequency frequency
	 */
	public RealtimeInstrumentMarker(Frequency frequency) {

		this(frequency, null);
	}

	/**
	 * @param frequency frequency
	 * @param label label
	 */
	public RealtimeInstrumentMarker(Frequency frequency, String label) {

		super(frequency, label);
		__useAdjClose = false;
		__marker = " ";
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see qy.jalgotrade.utils.plotter.Series#getMarker()
	 */
	@Override
	public String getMarker() {

		return __marker;
	}

	/**
	 * 
	 * @param marker marker
	 */
	public void setMarker(String marker) {

		__marker = marker;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see qy.jalgotrade.utils.plotter.Series#needColor()
	 */
	@Override
	public boolean needColor() {

		return true;
	}

	/**
	 * 
	 * @param useAdjClose useAdjClose
	 */
	public void setUseAdjClose(boolean useAdjClose) {

		// Force close/adj_close instead of price.
		__useAdjClose = useAdjClose;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see qy.jalgotrade.utils.plotter.Series#getValue(java.time.ZonedDateTime)
	 */
	@Override
	public Double getValue(ZonedDateTime dateTime) {

		// If not using candlesticks, the return the closing price.
		Bar bar = getValues().get(dateTime);
		if (bar != null) {
			if (__useAdjClose) {
				return bar.getAdjClose();
			} else {
				return bar.getClose();
			}
		} else {
			return Double.NaN;
		}
	}
}
